//
//  KSPlatformUtil.m
//  KSObjcUtilDemo
//
//  Created by Mac on 2020/5/7.
//  Copyright © 2020 kong. All rights reserved.
//

#import "KSPlatformUtil.h"
#import <sys/utsname.h>

@implementation KSPlatformUtil

KSPlatformType ks_platform(void){
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString*phoneType = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
    
    NSDictionary<NSString*,NSNumber*>* dic = @{
        @"iPhone1,1":@(KSPlatform2G),
        @"iPhone1,2":@(KSPlatform3G),
        @"iPhone2,1":@(KSPlatform3GS),
        @"iPhone3,1":@(KSPlatform4),
        @"iPhone3,2":@(KSPlatform4),
        @"iPhone3,3":@(KSPlatform4),
        @"iPhone4,1":@(KSPlatform4S),
        @"iPhone5,1":@(KSPlatform5),
        @"iPhone5,2":@(KSPlatform5),
        @"iPhone5,3":@(KSPlatform5C),
        @"iPhone5,4":@(KSPlatform5C),
        @"iPhone6,1":@(KSPlatform5S),
        @"iPhone6,2":@(KSPlatform5S),
        @"iPhone7,1":@(KSPlatform6P),
        @"iPhone7,2":@(KSPlatform6),
        @"iPhone8,1":@(KSPlatform6S),
        @"iPhone8,2":@(KSPlatform6SP),
        @"iPhone8,4":@(KSPlatformSE),
        @"iPhone9,1":@(KSPlatform7),
        @"iPhone9,2":@(KSPlatform7P),
        @"iPhone9,3":@(KSPlatform7),
        @"iPhone9,4":@(KSPlatform7P),
        @"iPhone10,1":@(KSPlatform8),
        @"iPhone10,4":@(KSPlatform8),
        @"iPhone10,2":@(KSPlatform8P),
        @"iPhone10,5":@(KSPlatform8P),
        @"iPhone10,3":@(KSPlatformX),
        @"iPhone10,6":@(KSPlatformX),
        @"iPhone11,8":@(KSPlatformXR),
        @"iPhone11,2":@(KSPlatformXS),
        @"iPhone11,4":@(KSPlatformXSMax),
        @"iPhone11,6":@(KSPlatformXSMax),
        @"iPhone12,1":@(KSPlatform11),
        @"iPhone12,3":@(KSPlatform11Pro),
        @"iPhone12,5":@(KSPlatform11ProMax),
        @"iPhone12,8":@(KSPlatformSE2),
        @"iPhone13,1":@(KSPlatform12Mini),
        @"iPhone13,2":@(KSPlatform12),
        @"iPhone13,3":@(KSPlatform12Pro),
        @"iPhone13,4":@(KSPlatform12ProMax),
        @"iPhone14,2":@(KSPlatform13Pro),
        @"iPhone14,3":@(KSPlatform13ProMax),
        @"iPhone14,4":@(KSPlatform13Mini),
        @"iPhone14,5":@(KSPlatform13),
        @"iPhone14,6":@(KSPlatformSE3),
        @"iPhone14,7":@(KSPlatform14),
        @"iPhone14,8":@(KSPlatform14Plus),
        @"iPhone15,2":@(KSPlatform14Pro),
        @"iPhone15,3":@(KSPlatform14ProMax),
        @"iPad1,1":@(KSPlatformPad),
        @"iPad2,1":@(KSPlatformPad2),
        @"iPad2,2":@(KSPlatformPad2),
        @"iPad2,3":@(KSPlatformPad2),
        @"iPad2,4":@(KSPlatformPad2),
        @"iPad2,5":@(KSPlatformPadMini),
        @"iPad2,6":@(KSPlatformPadMini),
        @"iPad2,7":@(KSPlatformPadMini),
        @"iPad3,1":@(KSPlatformPad3),
        @"iPad3,2":@(KSPlatformPad3),
        @"iPad3,3":@(KSPlatformPad3),
        @"iPad3,4":@(KSPlatformPad4),
        @"iPad3,5":@(KSPlatformPad4),
        @"iPad3,6":@(KSPlatformPad4),
        @"iPad4,1":@(KSPlatformPadAir),
        @"iPad4,2":@(KSPlatformPadAir),
        @"iPad4,3":@(KSPlatformPadAir),
        @"iPad4,4":@(KSPlatformPadMini2),
        @"iPad4,5":@(KSPlatformPadMini2),
        @"iPad4,6":@(KSPlatformPadMini2),
        @"iPad4,7":@(KSPlatformPadMini3),
        @"iPad4,8":@(KSPlatformPadMini3),
        @"iPad4,9":@(KSPlatformPadMini3),
        @"iPad5,1":@(KSPlatformPadMini4),
        @"iPad5,2":@(KSPlatformPadMini4),
        @"iPad5,3":@(KSPlatformPadAir2),
        @"iPad5,4":@(KSPlatformPadAir2),
        @"iPad6,3":@(KSPlatformPadPro97),
        @"iPad6,4":@(KSPlatformPadPro97),
        @"iPad6,7":@(KSPlatformPadPro129),
        @"iPad6,8":@(KSPlatformPadPro129),
        @"iPad6,11":@(KSPlatformPad5),
        @"iPad6,12":@(KSPlatformPad5),
        @"iPad7,1":@(KSPlatformPadPro1292),
        @"iPad7,2":@(KSPlatformPadPro1292),
        @"iPad7,3":@(KSPlatformPadPro105),
        @"iPad7,4":@(KSPlatformPadPro105),
        @"iPad7,5":@(KSPlatformPad6),
        @"iPad7,6":@(KSPlatformPad6),
        @"iPad7,11":@(KSPlatformPad7),
        @"iPad7,12":@(KSPlatformPad7),
        @"iPad8,1":@(KSPlatformPadPro110),
        @"iPad8,2":@(KSPlatformPadPro110),
        @"iPad8,3":@(KSPlatformPadPro110),
        @"iPad8,4":@(KSPlatformPadPro110),
        @"iPad8,5":@(KSPlatformPadPro1293),
        @"iPad8,6":@(KSPlatformPadPro1293),
        @"iPad8,7":@(KSPlatformPadPro1293),
        @"iPad8,8":@(KSPlatformPadPro1293),
        @"iPad8,9":@(KSPlatformPadPro1102),
        @"iPad8,10":@(KSPlatformPadPro1102),
        @"iPad8,11":@(KSPlatformPadPro1294),
        @"iPad8,12":@(KSPlatformPadPro1294),
        @"iPad11,1":@(KSPlatformPadMini5),
        @"iPad11,2":@(KSPlatformPadMini5),
        @"iPad14,1":@(KSPlatformPadMini6),
        @"iPad14,2":@(KSPlatformPadMini6),
        @"iPad11,3":@(KSPlatformPadAir3),
        @"iPad11,4":@(KSPlatformPadAir3),
        @"iPad11,6":@(KSPlatformPad8),
        @"iPad11,7":@(KSPlatformPad8),
        @"iPad12,1":@(KSPlatformPad9),
        @"iPad12,2":@(KSPlatformPad9),
        @"iPad13,1":@(KSPlatformPadAir4),
        @"iPad13,2":@(KSPlatformPadAir4),
        @"iPad13,4":@(KSPlatformPadPro1103),
        @"iPad13,5":@(KSPlatformPadPro1103),
        @"iPad13,6":@(KSPlatformPadPro1103),
        @"iPad13,7":@(KSPlatformPadPro1103),
        @"iPad13,8":@(KSPlatformPadPro1295),
        @"iPad13,9":@(KSPlatformPadPro1295),
        @"iPad13,10":@(KSPlatformPadPro1295),
        @"iPad13,11":@(KSPlatformPadPro1295),
        @"iPad13,16":@(KSPlatformPadAir5),
        @"iPad13,17":@(KSPlatformPadAir5),
        @"AirPods1,1":@(KSPlatformAirPods1),
        @"AirPods2,1":@(KSPlatformAirPods2),
        @"iProd8,1":@(KSPlatformAirPodsPro),
        @"AppleTV2,1":@(KSPlatformTV2),
        @"AppleTV3,1":@(KSPlatformTV3),
        @"AppleTV3,2":@(KSPlatformTV3),
        @"AppleTV5,3":@(KSPlatformTV4),
        @"AppleTV6,2":@(KSPlatformTV4K),
        @"AppleTV11,1":@(KSPlatformTV4K2),
        @"Watch1,1":@(KSPlatformWatch1),
        @"Watch1,2":@(KSPlatformWatch1),
        @"Watch2,6":@(KSPlatformWatchS1),
        @"Watch2,7":@(KSPlatformWatchS1),
        @"Watch2,3":@(KSPlatformWatchS2),
        @"Watch2,4":@(KSPlatformWatchS2),
        @"Watch3,1":@(KSPlatformWatchS3),
        @"Watch3,2":@(KSPlatformWatchS3),
        @"Watch3,3":@(KSPlatformWatchS3),
        @"Watch3,4":@(KSPlatformWatchS3),
        @"Watch4,1":@(KSPlatformWatchS4),
        @"Watch4,2":@(KSPlatformWatchS4),
        @"Watch4,3":@(KSPlatformWatchS4),
        @"Watch4,4":@(KSPlatformWatchS4),
        @"Watch5,1":@(KSPlatformWatchS5),
        @"Watch5,2":@(KSPlatformWatchS5),
        @"Watch5,3":@(KSPlatformWatchS5),
        @"Watch5,4":@(KSPlatformWatchS5),
        @"Watch5,9":@(KSPlatformWatchSE),
        @"Watch5,10":@(KSPlatformWatchSE),
        @"Watch5,11":@(KSPlatformWatchSE),
        @"Watch5,12":@(KSPlatformWatchSE),
        @"Watch6,1":@(KSPlatformWatchS6),
        @"Watch6,2":@(KSPlatformWatchS6),
        @"Watch6,3":@(KSPlatformWatchS6),
        @"Watch6,4":@(KSPlatformWatchS6),
        @"Watch6,6":@(KSPlatformWatchS7),
        @"Watch6,7":@(KSPlatformWatchS7),
        @"Watch6,8":@(KSPlatformWatchS7),
        @"Watch6,9":@(KSPlatformWatchS7),
        @"Watch6,10":@(KSPlatformWatchSE2),
        @"Watch6,11":@(KSPlatformWatchSE2),
        @"Watch6,12":@(KSPlatformWatchSE2),
        @"Watch6,13":@(KSPlatformWatchSE2),
        @"Watch6,14":@(KSPlatformWatchS8),
        @"Watch6,15":@(KSPlatformWatchS8),
        @"Watch6,16":@(KSPlatformWatchS8),
        @"Watch6,17":@(KSPlatformWatchS8),
        @"Watch6,18":@(KSPlatformWatchUltra),
        @"AudioAccessory1,1":@(KSPlatformHomePod),
        @"AudioAccessory1,2":@(KSPlatformHomePod),
        @"AudioAccessory5,1":@(KSPlatformHomePodMini),
        @"iPod1,1":@(KSPlatformPodTouch),
        @"iPod2,1":@(KSPlatformPodTouch2),
        @"iPod3,1":@(KSPlatformPodTouch3),
        @"iPod4,1":@(KSPlatformPodTouch4),
        @"iPod5,1":@(KSPlatformPodTouch5),
        @"iPod7,1":@(KSPlatformPodTouch6),
        @"iPod9,1":@(KSPlatformPodTouch7),
        @"x86_64":@(KSPlatformSimulator),
    };
    
    NSNumber* number = [dic objectForKey:phoneType];
    if (number) {
        return number.integerValue;
    }

    return KSPlatformUnknow;
}

@end
